package com.jiangxiaofei.citycloud.mvp;

import android.content.Context;

import com.blankj.utilcode.util.EmptyUtils;
import com.jiangxiaofei.citycloud.bean.ParkDetailInfoBean;
import com.jiangxiaofei.citycloud.httpUtil.OnLoadDataIm;
import com.jiangxiaofei.citycloud.param.BaiduPlaceParam;
import com.jiangxiaofei.citycloud.param.GetPartParam;

/**
 * 作者: JiangXfei
 * 日期: 2017/9/20 0020
 */

public class CarPersenter implements CarConstant.GetBaiduPlacePersenter,
        CarConstant.GetParkPersenter, CarConstant.getParkDetailPersenter {
    private Context mContext;
    private CarConstant.GetBaiduPlaceModel getBaiduPlaceModel;
    private CarConstant.GetBaiduPlaceView getBaiduPlaceView;

    private CarConstant.GetParkModel getPartModel;
    private CarConstant.GetParkView getPartView;

    private CarConstant.getParkDetailModel getParkDetailModel;
    private CarConstant.getParkDetailView getParkDetailView;

    public CarPersenter(Context mContext, CarConstant.GetBaiduPlaceView getBaiduPlaceView) {
        this.mContext = mContext;
        this.getBaiduPlaceView = getBaiduPlaceView;
        getBaiduPlaceModel = new CarModel();
    }

    public CarPersenter(Context mContext, CarConstant.GetParkView getPartView) {
        this.mContext = mContext;
        this.getPartView = getPartView;
        getPartModel = new CarModel();
    }

    public CarPersenter(Context mContext, CarConstant.getParkDetailView getParkDetailView) {
        this.mContext = mContext;
        this.getParkDetailView = getParkDetailView;
        this.getParkDetailModel = new CarModel();
    }

    //获取百度place
    @Override
    public void getPlace() {
        BaiduPlaceParam baiduPlace = getBaiduPlaceView.getBaiduPlace();
        if (EmptyUtils.isNotEmpty(baiduPlace)) {
            getBaiduPlaceModel.setBaiduPlace(mContext, baiduPlace, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        getBaiduPlaceView.getPlaceSuccess(o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }

    //获取停车场数据
    @Override
    public void getPark() {
        GetPartParam part = getPartView.getPark();
        if (EmptyUtils.isNotEmpty(part)) {
            getPartModel.getPark(mContext, part, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        getPartView.onSuccessPart(o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }

    @Override
    public void getParkDetail() {
        getParkDetailView.showLoading();
        String parkSeq = getParkDetailView.getParkSeq();
        if (EmptyUtils.isNotEmpty(parkSeq)) {
            getParkDetailModel.getPartDetail(mContext, parkSeq, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        getParkDetailView.onSuccessParkDetail((ParkDetailInfoBean.ParkDetailsInfoBean) o);
                        getParkDetailView.hideLoading();
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }
}
